package com.bkgy.modularbx.rule_edit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bkgy.commom.model.QueryDTO;
import com.bkgy.modularbx.rule_edit.domain.RuleEdit;
import com.bkgy.modularbx.rule_edit.dto.RuleEditUpdateDto;
import com.bkgy.modularbx.rule_edit.dto.SearchCondition;
import com.bkgy.modularbx.rule_edit.service.RuleEditService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/rule-edit")
@Tag(name = "规则编辑管理", description = "规则编辑表相关接口")
@RequiredArgsConstructor
public class RuleEditController {

    private final RuleEditService ruleEditService;

    @PostMapping("/add")
    @Operation(summary = "新增规则编辑数据")
    public ResultData<Void> addRuleEdit(@RequestBody @Valid RuleEdit ruleEdit) {
        log.info("新增规则编辑数据请求: {}", ruleEdit);
        return ruleEditService.addRuleEdit(ruleEdit);
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询规则编辑数据")
    public ResultData<Page<RuleEdit>> pageRuleEdit(@RequestBody QueryDTO<SearchCondition> queryDTO) {
        return ruleEditService.pageRuleEdit(queryDTO);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除规则编辑数据")
    public ResultData<Void> deleteRuleEdit(@RequestParam("indocno") Integer indocno) {
        log.info("删除规则编辑数据请求，ID: {}", indocno);
        return ruleEditService.deleteRuleEdit(indocno);
    }

    @PostMapping("/updateRuleEditById")
    @Operation(summary = "更新规则编辑数据")
    public ResultData<Void> updateRuleEdit(@RequestBody @Valid RuleEditUpdateDto ruleEditUpdateDto) {
        log.info("更新规则编辑数据请求: {}", ruleEditUpdateDto);
        return ruleEditService.updateRuleEdit(ruleEditUpdateDto);
    }

    @PostMapping("/findById")
    @Operation(summary = "根据ID查询规则编辑数据")
    public ResultData<RuleEdit> findById(@RequestBody @Parameter(description = "主键ID") Integer indocno) {
        return ruleEditService.findById(indocno);
    }
}